from django import newforms as forms
from google.appengine.api import users
import models
import re
from google.appengine.ext.db import djangoforms

def split_tags(s):
		tags = list(set([t.strip() for t in re.split('[,;\\/\\\\]*', s) if t != ''])) #uniq
		return tags

class PostForm(forms.Form):
	title = forms.CharField()
	content = forms.CharField(widget=forms.Textarea())
	tags = forms.CharField()
	def save(self,currnet_user):
		post = models.Post(tags = split_tags(self.clean_data['tags']),title = self.clean_data['title'],content = self.clean_data['content'],author = currnet_user)
		post.put()

		
class CommentForm(forms.Form):
#	class CommentForm(forms.Form):
	comments_title = forms.CharField(widget=forms.Textarea())
	comments_content = forms.CharField(widget=forms.Textarea())
	def save(self,post_key):
		comment = models.Comments(post = post_key,comments_title = self.clean_data['comments_title'], comments_content = self.clean_data['comments_content'])
		comment.put()